<?php
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/message.php';
require_once '../../model/users.php';
include_once("../../includes/classes/paging_htacess.php");
require_once '../../redirect.php';
## Create Objects
/*******************************/
$msgObj = new Model_Message();
$userObj = new Model_Users();
/*******************************/

checkUserLogin();

$userId = $_SESSION['getbids_id'];
$userDetArray = $userObj->getUserDetailsByUserId($userId);
$smarty->assign('userDetArray',$userDetArray);


$msgArray = $msgObj->getAllMessageByToId($userId);
$total_rows= count($msgArray);
# --------- Pagination Part1 ---------- #
$page = $_GET['id1'];
if(!isset($_GET['id1']))
$page = 1;
else
$page = $page;
$smarty->assign("page",$page);
$rowsperpage = 10; 
$offset = $rowsperpage * ($page-1);
$smarty->assign("total_rows",$total_rows);
$smarty->assign("rowsperpage",$rowsperpage);
if($total_rows > 0) 
{
	$msgArray = $msgObj->getAllMessageByToId($userId,$rowsperpage, $offset);
	$total_pages = ceil($total_rows / $rowsperpage);
	
	$i=0;
	foreach($msgArray as $msg)
	{
		$senderDetArr = $userObj->getUserDetailsByUserId($msg['from_id']);
		$msgArray[$i]['sender_name'] = $senderDetArr['first_name']." ".$senderDetArr['last_name'];
		$msgArray[$i]['image'] = $senderDetArr['user_avatar'];
		$msgArray[$i]['ago'] = ago($msg['send_date']);
		$i++;
	}
	$smarty->assign("msgArray", $msgArray);
	//echo"<pre>";print_R($msgArray);die();
	$showing   = !isset($_GET["id1"]) ? 1 : $page;
	$firstlink = "mymessages";
	$baselink  = $firstlink;
	$pagenation = pagination($total_pages, $show, $showing, $firstlink, $baselink,"", "myaccount");
	
	$smarty->assign("pagenation",$pagenation);
	$smarty->assign("page",$page);
}

if($_SESSION['msg'] != ''){
	$smarty->assign("msg", $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

$active = "myaccount";
$smarty->assign("active", $active);
$subactive = "mymessages";
$smarty->assign("subactive", $subactive);

$mainmenu='2';
$smarty->assign("mainmenu",$mainmenu);



$smarty->display(TEMPLATEDIR . '/modules/myaccount/mymessages.tpl');
?>